<template>
  <template v-if="props.stageComparisonInfo?.length">
    <div
      class="emission-content"
      v-for="item in stageComparisonInfo"
      :key="item.lifeCycleStageCode"
    >
      <el-collapse v-model="activeNames">
        <el-collapse-item :name="item.lifeCycleStageCode">
          <template #title>
            <div class="chart-title">
              <CIcon
                class="fold__icon"
                :class="activeNames.includes(item.lifeCycleStageCode as any) ? '' : 'fold__icon--up'"
                type="c-mian-xia"
              ></CIcon>
              <img
                class="stage_img"
                :src="require(`@/assets/images/icon_${item.lifeCycleStageCode}.png`)"
              />
              <span class="title-name">{{ ProcessStageMap[item.lifeCycleStageCode] }}</span>
            </div>
          </template>
          <div class="table-list">
            <template
              v-for="(itemChildren, index) in item.comparisonBaseInfo"
              :key="itemChildren.name"
            >
              <div
                class="list-item"
                v-show="
                  (isOnlyShowDiff && itemChildren.emissionLeft != itemChildren.emissionRight) ||
                  index == 0 ||
                  !isOnlyShowDiff
                "
              >
                <div class="table-l-r-usually">
                  <div class="item-tit g-ell" :class="{ 'item-total': index == 0 }" v-ellTooltip>
                    {{ index == 0 ? '总量' : itemChildren.name }}
                  </div>
                  <div class="item-content">
                    <span class="num">{{
                      itemChildren.emissionLeft || itemChildren.emissionLeft === 0
                        ? renderResultUnit(itemChildren.emissionLeft)
                        : '-'
                    }}</span>
                    <el-progress
                      :id="itemChildren.name"
                      :style="{
                        opacity: itemChildren.emissionLeft > itemChildren.emissionRight ? 1 : 0.1
                      }"
                      :stroke-width="20"
                      :percentage="getPercentage(itemChildren.emissionLeft, item.maxEmission)"
                      color="#03AC82"
                    />
                  </div>
                </div>
                <div class="table-l-r-usually">
                  <div class="item-content">
                    <span class="num" v-if="rightModel"
                      >{{
                        itemChildren.emissionRight || itemChildren.emissionRight === 0
                          ? renderResultUnit(itemChildren.emissionRight)
                          : '-'
                      }}
                    </span>
                    <el-progress
                      v-if="rightModel"
                      :id="itemChildren.name"
                      :style="{
                        opacity: itemChildren.emissionRight > itemChildren.emissionLeft ? 1 : 0.1
                      }"
                      :stroke-width="20"
                      :percentage="getPercentage(itemChildren.emissionRight, item.maxEmission)"
                      color="#308BF2"
                    />
                  </div>
                  <div
                    v-if="rightModel || index == 0"
                    class="item-tit g-ell"
                    :class="{ 'item-total': index == 0 }"
                    style="text-align: right"
                  >
                    {{ index == 0 ? '总量' : itemChildren.name }}
                  </div>
                </div>
              </div>
            </template>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
  </template>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { withDefaults, defineProps } from 'vue';
import { ProcessStageCodeEnum, ProcessStageMap } from '@/constants/enum';
import type { GetComparisonListResult } from '@/apis/pcf/pcfForm/model/pcfFormModel';
import { renderResultUnit } from '@/utils';
interface CardListProps {
  // 左侧模型
  leftModel: any;
  // 右侧模型
  rightModel: any;
  // 阶段对比信息
  stageComparisonInfo?: GetComparisonListResult['stageComparisonInfo'];
  isOnlyShowDiff?: boolean;
}

const props = withDefaults(defineProps<CardListProps>(), {
  isOnlyShowDiff: false
});

function getPercentage(numVal: number, maxValue: number) {
  return (numVal / maxValue) * 100;
}
const activeNames = ref([ProcessStageCodeEnum.SUPPLY_CHAIN_STAGE]);
</script>
<style lang="scss" scoped>
.emission-content {
  margin-top: 16px;
  background: #ffffff;
  border: 1px solid #fff;
  border-radius: 6px;
  .chart-title {
    padding-left: 16px;
    display: flex;
    align-items: center;
    max-height: 48px;
    .title-name {
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 550;
      color: #0a1f33;
      line-height: 22px;
    }
  }

  .table-list {
    padding: 0 16px;
    .list-item {
      display: flex;
      background: #f3f7fb;
    }

    .table-l-r-usually {
      display: flex;
      flex: 1;
      height: 40px;

      border: 1px solid #ebeff2;
      .item-total {
        color: #0a1f33 !important;
      }

      .item-tit {
        flex-basis: 160px;
        padding: 9px 16px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #435970;
        line-height: 22px;
      }
      .item-content {
        position: relative;
        padding: 10px 0 10px 16px;
        flex-grow: 1;
        text-align: center;
        line-height: 40px;

        .num {
          z-index: 999;
          position: absolute;
          left: calc(50% - 20px);
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #0a1f33;
          line-height: 22px;
        }
      }

      .item-content:nth-child(1) {
        padding: 10px 16px 10px 0;
      }

      ::v-deep .el-progress__text {
        display: none !important;
      }

      ::v-deep .el-progress-bar__outer {
        border-radius: 0;
        background: #f3f7fb;
      }

      ::v-deep .el-progress-bar__inner {
        border-radius: 0;
      }
    }
    .table-l-r-usually:nth-child(1) {
      border-right: none;
      border-bottom: none;
      ::v-deep .el-progress {
        transform: rotate(180deg);
      }
    }
    .table-l-r-usually:nth-child(2) {
      border-bottom: none;
    }

    .list-item:nth-child(n + 2) {
      background: #fff;
      ::v-deep .el-progress-bar__outer {
        border-radius: 0;
        background: #fff;
      }
    }
    .list-item:first-child {
      .table-l-r-usually:nth-child(1) {
        border-radius: 3px 0px 0px 0px;
      }
      .table-l-r-usually:nth-child(2) {
        border-radius: 0px 3px 0px 0px;
      }
    }
    .list-item:last-child {
      .table-l-r-usually {
        border-bottom: 1px solid #ebeff2;
      }
    }
  }

  ::v-deep .el-collapse {
    border: none;
  }
  ::v-deep .el-collapse-item__header {
    position: relative;
  }
  ::v-deep .el-collapse-item__arrow {
    display: none;
    // position: absolute;
    // left: 16px;
    // top: 16px;
  }

  ::v-deep .el-collapse-item__wrap {
    border: none;
  }
  ::v-deep .el-collapse-item__header {
    border: none;
  }
}
.fold__icon {
  display: inline-block;
  font-size: 12px;
  transform: rotate(0deg);
  transition: transform 0.3s;
  &.fold__icon--up {
    transform: rotate(-90deg);
  }
}
.stage_img {
  width: 16px;
  height: 16px;
  margin: 0 4px 0 6px;
}
</style>
